# https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=3250b1b50f5254396edf12e7cd68da2f

# 逆两个参数
# params
# encSecKey

# /api/song/enhance/player/url/v1  后面进行了一个替换操作 就与原始的url是一致的

"""
encodeType: "aac"
ids: "[1340439829]" 歌曲id
level: "standard"
中途添加了 一个 csrf_token参数 这是登录用户才会有的
"""

""" 
var bKP5U = window.asrsea(JSON.stringify(i7b), i7b 就是上面4个参数 转json字符串
 bvg3x(["流泪", "强"]), ==> 固定值 "010001"
 bvg3x(Wo9f.md), ===>  也是固定的 '00e0b509f6259df8642dbc35662901477df22677ec152b5ff68ace615bb7b725152b3ab17a876aea8a5aa76d2e417629ec4ee341f56135fccf695280104e0312ecbda92557c93870114af6c9d05c4f7f0c3685b7a46bee255932575cce10b424d813cfe4875d3e82047b97ddef52741d546b8e289dc6935b3ece0462db0a22b8e7'
 
bvg3x(["爱心", "女孩", "惊恐", "大笑"])); ===> '0CoJUm6Qyw8W8jud'
  
e7d.data = j7c.cq8i({
    params: bKP5U.encText,  ==> 找到参数1    两次AES
    encSecKey: bKP5U.encSecKey ==> 找到参数2 这两个是从bKP5U提取的  一次RSA
    参数是固定的
    搞定 windows.asrsea()就行
})
"""
import subprocess
from functools import partial

subprocess.Popen = partial(subprocess.Popen, encoding='utf-8')
import execjs
import json
import requests

data = {
    "ids": f"[{input('请输入一个id:')}]",
    "level": "standard",
    "encodeType": "aac",
    "csrf_token": "3250b1b50f5254396edf12e7cd68da2f"
}

s = json.dumps(data)
ctx = execjs.compile(open('wyy.js', 'r', encoding='utf-8').read())
dic = ctx.call("fn", s)
print(dic)

read_params = {
    'params': dic['encText'],
    'encSecKey': dic['encSecKey'],
}

url = 'https://music.163.com/weapi/song/enhance/player/url/v1?csrf_token=3250b1b50f5254396edf12e7cd68da2f'
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
}
resp = requests.post(url, data=read_params, headers=headers)
print(resp.json())